package airthmetic.exercise.arr;


public class _189_轮转数组 {

    public static void rotate(int[] nums, int k) {

        if (nums == null || nums.length == 1){
            return;
        }
        if (k <= 0) {
            return;
        }
        int p1 = 0;
        int p2 = nums.length - 1;
        int moveSize = p2 - p1;
        while (k > 0) {
            int move = nums[p2];
            for (int i = moveSize; i >0; i--) {
                nums[i] = nums[i-1];
            }
            nums[p1] = move;
            k--;
        }


    }

    public static void main(String[] args) {
        int k = 3;
        int[] nums = new int[]{1, 2, 3, 4, 5, 6, 7};
        rotate(nums,k);

        for (int num : nums) {
            System.out.println(num);
        }

    }
}
